const fs = require('fs');

// 读取并解析data.js
const content = fs.readFileSync('data.js', 'utf8');
const arrayStart = content.indexOf('[');
const arrayEnd = content.lastIndexOf(']') + 1;
const gameList = eval(`(${content.substring(arrayStart, arrayEnd)})`);

// 读取text.txt并处理新代码
const newCodes = fs.readFileSync('text.txt', 'utf8')
  .split(/\r?\n/)
  .map(line => line.trim())
  .filter(Boolean);

// 添加新条目并去重
newCodes.forEach(code => {
  if (!gameList.some(item => item.shareCode === code)) {
    gameList.push({ completed: false, shareCode: code });
  }
});

// 生成新的数组字符串
const newArray = gameList.map(item => 
  `{
  completed : ${item.completed},
  shareCode:"${item.shareCode.replace(/"/g, '\\"')}"
}`).join(',\n');

// 更新文件内容并写入
const updatedContent = content.substring(0, arrayStart) + 
  `[\n${newArray}\n]` + 
  content.substring(arrayEnd);

fs.writeFileSync('data.js', updatedContent);
console.log('数据已成功更新！');



